package test.http;

import io.undertow.Undertow;
import io.undertow.util.Headers;

import java.util.Objects;

public class UndertowPlainTextServer {
    public static void main(String[] args) {
        Undertow server = Undertow.builder()
                .addHttpListener(8080, "localhost")
                .setHandler(exchange -> {
                    if (Objects.equals(exchange.getRequestURI(), "/plain-text")) {
                        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
                        exchange.getResponseHeaders().remove("Connection");
                        exchange.getResponseSender().send("Plain Text");
                    } else {
                        exchange.setStatusCode(404);
                        exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "text/plain");
                        exchange.getResponseSender().send("Not Found");
                    }
                }).build();
        server.start();
    }
}
